package cn.edu.besti.cs1723.Z2316;

import week3rd.LinkedQueue;
import week4th.jsjf.ArrayOrderedList;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Huffman {

    public Huffman() {


    }

    public float[] perCount(String path) throws FileNotFoundException {
        float[] per = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        String[] passage = new String[500];
        FileReader file = new FileReader(path);
        BufferedReader reader = new BufferedReader(file);
        try {
            passage = reader.readLine().split("");
        } catch (IOException e) {
            e.printStackTrace();
        }

        for (int i = 0; i < passage.length; i++) {
            switch (passage[i]) {
                case "a":
                    per[1]++;
                    break;
                case "b":
                    per[2]++;
                    break;
                case "c":
                    per[3]++;
                    break;
                case "d":
                    per[4]++;
                    break;
                case "e":
                    per[5]++;
                    break;
                case "f":
                    per[6]++;
                    break;
                case "g":
                    per[7]++;
                    break;
                case "h":
                    per[8]++;
                    break;
                case "i":
                    per[9]++;
                    break;
                case "j":
                    per[10]++;
                    break;
                case "k":
                    per[11]++;
                    break;
                case "l":
                    per[12]++;
                    break;
                case "m":
                    per[13]++;
                    break;
                case "n":
                    per[14]++;
                    break;
                case "o":
                    per[15]++;
                    break;
                case "p":
                    per[16]++;
                    break;
                case "q":
                    per[17]++;
                    break;
                case "r":
                    per[18]++;
                    break;
                case "s":
                    per[19]++;
                    break;
                case "t":
                    per[20]++;
                    break;
                case "u":
                    per[21]++;
                    break;
                case "v":
                    per[22]++;
                    break;
                case "w":
                    per[23]++;
                    break;
                case "x":
                    per[24]++;
                    break;
                case "y":
                    per[25]++;
                    break;
                case "z":
                    per[26]++;
                    break;
                case " ":
                    per[0]++;
                    break;
                case ",":
                    per[27]++;
            }
        }
        int sum = 0;
        for (int i = 0; i < per.length; i ++) {
            sum += per[i];
        }
        for (int i = 0; i < per.length; i++) {
            per[i] /= sum;
        }

        Sorting sort = new Sorting();
        sort.bubbleSort(per);
        return per;
    }

}






